package net.yla.smartbus.core.constants;

import com.alibaba.fastjson.annotation.JSONType;
import net.yla.smartbus.core.exception.EnumNotFoundException;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 审核状态枚举
 * @author zhangchengcheng
 * @date 2019/7/12 15:08
 */
@JSONType(serializeEnumAsJavaBean = true)
public enum AuditStatusEnum {
	/**
	 * 待审核
	 */
    UNTREATED(0,"待审核"),
	/**
	 * 审核通过
	 */
    PASS(1,"审核通过"),

	/**
	 * 审核不通过
	 */
    NOT_PASS(2,"审核不通过"),
    /**
     * 待申请
     */
    APPLY(3,"待申请");

    private int code;
    private String desc;

    AuditStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    private static final Map<Integer, AuditStatusEnum> BY_VALUE_MAP = new LinkedHashMap<>();

    static {
        for (AuditStatusEnum auditStatusEnum : AuditStatusEnum.values()) {
            BY_VALUE_MAP.put(auditStatusEnum.getCode(), auditStatusEnum);
        }
    }

    /**
     * 根据code查询对应的处理结果类型枚举
     */
    public static AuditStatusEnum convertCode2Enum(int code) throws EnumNotFoundException {
        if (!BY_VALUE_MAP.containsKey(code)) {
            throw new EnumNotFoundException("枚举对应的code" + code + "不存在");
        }
        return BY_VALUE_MAP.get(code);
    }

    /**
     * 根据枚举name查询对应的处理结果类型枚举
     */
    public static AuditStatusEnum convertStr2Enum(String str) throws EnumNotFoundException {
        try {
            return AuditStatusEnum.valueOf(str);
        } catch (Exception e) {
            throw new EnumNotFoundException("枚举对应常量" + str + "不存在");
        }
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getName() {
        return this.name();
    }
}
